﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace WebApplication1
{
    public partial class cdissue : System.Web.UI.Page
    {
        SqlConnection cnn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                cnn.Open();
                SqlCommand cmd1 = new SqlCommand("select distinct accno from account", cnn);
                SqlDataReader dr = cmd1.ExecuteReader();
                DropDownList1.Items.Add("Select");
                while (dr.Read())
                    DropDownList1.Items.Add(Convert.ToString(dr.GetValue(0)));
                dr.Close();
                cnn.Close();
            }
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                HyperLink lnkiss = e.Row.FindControl("lnkiss") as HyperLink;
                HyperLink lnkren = e.Row.FindControl("lnkrenew") as HyperLink;
                HyperLink lnkret = e.Row.FindControl("lnkreturn") as HyperLink;
                Label literalstate = e.Row.FindControl("litstate") as Label;

                if (literalstate != null)
                {
                    string state = literalstate.Text;
                    if (state.Equals("Request")||state.Equals("Reserve"))
                    {
                        lnkiss.Enabled = true;
                        lnkren.Enabled = false;
                        lnkret.Enabled = false;
                       
                    }
                    else if(state.Equals("Issued"))
                    {
                        lnkren.Enabled = true;
                        lnkret.Enabled = true;
                        lnkiss.Enabled=false;
                    }

                }

            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            cnn.Open();
            SqlCommand cmd = new SqlCommand("select issno,cdno,custno,status from cdissue where custno='" + DropDownList1.SelectedItem + "'", cnn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            ds.Clear();
            da.Fill(ds, "cd");
            GridView1.Visible = true;
            GridView1.DataSource = ds;
            GridView1.DataBind();
            cnn.Close();
        }
       
    }
}